//
//  UIView+Extension.m
//  JKFloatingBox
//
//  Created by 王冲 on 2019/9/18.
//  Copyright © 2019 王冲. All rights reserved.
//

#import "UIView+Extension.h"

@implementation UIView (Extension)

#pragma mark x
-(void)setJk_x:(CGFloat)jk_x{
    
    CGRect frame = self.frame;
    frame.origin.x = jk_x;
    self.frame = frame;
}

-(CGFloat)jk_x{
    
    return self.frame.origin.x;
}

#pragma mark y
-(void)setJk_y:(CGFloat)jk_y{
    CGRect frame = self.frame;
    frame.origin.y = jk_y;
    self.frame = frame;
}
-(CGFloat)jk_y{
    return self.frame.origin.y;
}

#pragma mark width
-(void)setJk_width:(CGFloat)jk_width{
    
    CGRect frame = self.frame;
    frame.size.width = jk_width;
    self.frame = frame;
}

-(CGFloat)jk_width{
    return self.frame.size.width;
}

#pragma mark height
-(void)setJk_height:(CGFloat)jk_height{
    CGRect frame = self.frame;
    frame.size.height = jk_height;
    self.frame = frame;
}

-(CGFloat)jk_height{
    return self.frame.size.height;
}

#pragma mark centerX

-(void)setJk_centerX:(CGFloat)jk_centerX{
    CGPoint center = self.center;
    center.x = jk_centerX;
    self.center = center;
}

-(CGFloat)jk_centerX{
    
    return self.center.x;
}

#pragma mark centerY

-(void)setJk_centerY:(CGFloat)jk_centerY{
    
    CGPoint center = self.center;
    center.y = jk_centerY;
    self.center = center;
}

-(CGFloat)jk_centerY{
    return self.center.y;
}


#pragma mark origin

-(CGPoint)jk_origin{
    return self.frame.origin;
}
-(void)setJk_origin:(CGPoint)jk_origin{
    CGRect frame = self.frame;
    frame.origin = jk_origin;
    self.frame = frame;
}

#pragma mark size
-(void)setJk_size:(CGSize)jk_size{
    CGRect frame = self.frame;
    frame.size = jk_size;
    self.frame = frame;
}

-(CGSize)jk_size{
    return self.frame.size;
}

#pragma mark 上
-(CGFloat)jk_top{
    return self.frame.origin.y;
}

-(void)setJk_top:(CGFloat)jk_top{
    CGRect frame = self.frame;
    frame.origin.y = jk_top;
    self.frame = frame;
}

#pragma mark 左
-(CGFloat)jk_left{
    return self.frame.origin.x;
}

-(void)setJk_left:(CGFloat)jk_left{
    CGRect frame = self.frame;
    frame.origin.x = jk_left;
    self.frame = frame;
}

#pragma mark 下
-(CGFloat)jk_bottom{
    return self.frame.origin.y + self.frame.size.height;
}

-(void)setJk_bottom:(CGFloat)jk_bottom{
    CGRect frame = self.frame;
    frame.origin.y = jk_bottom - frame.size.height;
    self.frame = frame;
}

#pragma mark 右
-(CGFloat)jk_right{
    return self.frame.origin.x + self.frame.size.width;
}

-(void)setJk_right:(CGFloat)jk_right{
    CGRect frame = self.frame;
    frame.origin.x = jk_right - frame.size.width;
    self.frame = frame;
}

/**
 给继承于view的类添加 四周 阴影
 
 @param shadowRadius 阴影半径
 @param theColor 阴影的颜色
 @param size 阴影的偏移度：CGSizeMake(X[正的右偏移,负的左偏移], Y[正的下偏移,负的上偏移]);
 @param opacity 阴影的透明度
 */
- (void)cy_addShadowToViewShadowRadius:(CGFloat)shadowRadius withCornerRadius:(CGFloat)cornerRadius withColor:(UIColor *)theColor withShadowOffset:(CGSize)size withShadowOpacity:(float)opacity withIsClipsCorner:(BOOL)isClipsCorner {
    
    // 阴影颜色
    self.layer.shadowColor = theColor.CGColor;
    // 阴影的偏移 CGSizeMake(X[正的右偏移,负的左偏移], Y[正的下偏移,负的上偏移]);
    self.layer.shadowOffset = size;
    // 阴影透明度，默认0,不透明度(不透明度只要大于1就说明是有阴影的)
    self.layer.shadowOpacity = opacity;
    // 圆角的半径
    if (isClipsCorner) {
        self.layer.cornerRadius = cornerRadius;
        self.clipsToBounds =NO;
    }
    // 阴影半径，默认3
    self.layer.shadowRadius = shadowRadius;
}


@end
